﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dubbo.Rpc
{
    public abstract class AbstractExporter<T> : IExporter<T>
    {
        //protected readonly Logger   logger     = LoggerFactory.getLogger(getClass());

        private volatile bool unexported = false;

        public AbstractExporter(IInvoker<T> invoker)
        {
            if (invoker == null)
                throw new ArgumentNullException("service invoker == null");
            if (invoker.Url == null)
                throw new ArgumentNullException("service url == null");
            this.Invoker = invoker;
        }

        public IInvoker<T> Invoker { get; private set; }

        public virtual void Unexport()
        {
            if (unexported)
            {
                return;
            }
            unexported = true;
            Invoker.Destroy();
        }

        public override string ToString()
        {
            return Invoker.ToString();
        }
    }
}
